/* 管理所以自定义指令的模块 */

// 1.处理图片加载失败的指令
export const imgError = {
  inserted(el, bindings) {
    // console.log(el, bindings)
    // 如果src没有赋值, 给默认src
    el.src = el.src || bindings.value
    // 图片加载失败时触发的事件
    el.onerror = () => {
      el.src =
        bindings.value ||
        'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg'
    }
  },
  componentUpdated(el, bindings) {
    // 如果src没有赋值, 给默认src
    el.src = el.src || bindings.value
  },
}

// 2.自定义字体颜色的指令
export const color = {
  inserted(el, bindings) {
    el.style.color = bindings.value
  },
}
